package cc.wsyw126.java.nowcoder.sword_offer;


/**
 * Created by dp on 2017/4/19.
 * 请实现一个函数，用来判断一颗二叉树是不是对称的。注意，如果一个二叉树同此二叉树的镜像是同样的，定义其为对称的。
 */
public class IsSymmetrical {
    boolean isSymmetrical(TreeNode pRoot) {
        if (pRoot == null) return true;
        return judge(pRoot.left, pRoot.right);
    }

    private boolean judge(TreeNode left, TreeNode right) {
        if (left == null && right == null) return true;
        if (left != null && right != null)
            return left.val == right.val && judge(left.left, right.right) && judge(left.right, right.left);
        return false;
    }
}
